home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8283 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: gryphon.phoenix.net!usenet
  2. From: brucew@phoenix.net (Bruce Wedding)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem with a for loop
  5. Date: Sat, 02 Mar 1996 22:03:46 GMT
  6. Organization: BranPaul Systems
  7. Message-ID: <4hagk7$skq@gryphon.phoenix.net>
  8. References: <4h8g0l$1ot@nic.umass.edu>
  9. NNTP-Posting-Host: dial89.phoenix.net
  10. X-Newsreader: Moe's Newsreader    
  11.  
  12. In comp.lang.c
  13. ksexton@wilde.oit.umass.edu (Kevin M Sexton) wrote:
  14.  
  15. >for ( i = 0; WL[i] != NULL, i <= 10; i++ )
  16. >{
  17. >    AAL[i] = new char[strlen(WL[i])+1);
  18. >    strcpy(AAL[i], WL[i]);
  19. >}
  20. >
  21. >I realize that new belongs to C++, but that's not where the confusion 
  22. >lies.  WL is an array of pointers to strings.  WL[0]="./my_macro" and
  23. >WL[1]=NULL.  However, the for loop insists on continuing the loop even 
  24. >when i=1 and WL[i]=NULL.  Am I missing something?  I can't see what is 
  25. >wrong logically. 
  26.  
  27. You are misusing the comma operator.  The line WL[i] != NULL is
  28. evaluated then thrown away.  The only value used to end the loop
  29. is the  i <= 10;  What you need is a && in there instead of a
  30. comma.
  31.  
  32.  
  33. Bruce D. Wedding                        Have Compiler, Will Travel!
  34.               Perspicacious Programming Performed Promptly
  35. Katy, Texas, USA, Planet Earth, Milkyway Galaxy, Known Universe
  36.  
  37.